<template>
  <div class="merchant-inspection">
    <!-- 内容区域 -->
    <el-row :gutter="10">
      <el-col :xs="24" :sm="24" :md="16" :lg="16" :xl="16">
        <div>
          <!-- 指标统计 在页面的左上部分，占页面宽度的60% -->
          <div class="metric-statistics bg-white">
            <div class="title">指标统计</div>
            <div class="metric-content">
              <div class="metric-item">
                <svg-icon style="width: 42px;height: 42px;" icon-class="knowledgeIcon" />
                <!-- <i class="el-icon-collection knowledgeIcon"></i> -->
                <div>
                  <div class="metric-value knowledge">
                    {{ metric.knowledgeCount }}
                  </div>
                  <div class="metric-label">知识库数量</div>
                </div>
              </div>
              <div class="metric-item">
                <svg-icon style="width: 42px;height: 42px;" icon-class="documentIcon" />
                <!-- <i class="el-icon-tickets documentIcon"></i> -->
                <div>
                  <div class="metric-value document">
                    {{ metric.fileCount }}
                  </div>
                  <div class="metric-label">知识文档数量</div>
                </div>
              </div>
              <div class="metric-item">
                <!-- <i class="el-icon-collection-tag tagsIcon"></i> -->
                <svg-icon style="width: 42px;height: 42px;" icon-class="tagsIcon" />
                <div>
                  <div class="metric-value tags">{{ metric.flagCount }}</div>
                  <div class="metric-label">知识标签数量</div>
                </div>
              </div>
              <div class="metric-item">
                <svg-icon style="width: 42px;height: 42px;" icon-class="addKnowledgeIcon" />
                <!-- <i class="el-icon-document-add addKnowledgeIcon"></i> -->
                <div >
                  <div class="metric-value addKnowledge">
                    {{ metric.fileNewCount }}
                  </div>
                  <div class="metric-label">新增知识数量</div>
                </div>
              </div>
            </div>
          </div>
          <!-- 巡检趋势 位于指标统计的下方 在页面的左上部分，占页面宽度的60%-->
          <div class="inspection-trend bg-white">
            <div class="trend-title">
              <span>知识文档趋势</span>
              <el-select v-model="selectedYear" placeholder="选择年份">
                <el-option
                  v-for="item in yearList"
                  :key="item"
                  :label="item"
                  :value="item"
                ></el-option>
              </el-select>
            </div>
            <div id="trendChart" style="height: 300px"></div>
          </div>
        </div>
      </el-col>
      <el-col :xs="24" :sm="24" :md="8" :lg="8" :xl="8">
        <div>
          <!-- 消息提醒 位于页面的右上方，占页面宽度的40%-->
          <div class="message-reminder bg-white">
            <div class="reminder-header">
              <div class="reminder-title">消息提醒</div>
              <!-- <el-link type="primary">更多</el-link> -->
            </div>
            <ul>
              <li v-for="(msg, index) in messages" :key="index">
                <span class="msg-type">{{ msg.type }}</span>
                <span class="msg-content">{{ msg.content }}</span>
              </li>
            </ul>
          </div>
          <!-- 子机构排名和巡检员排名 tab格式 位于消息提醒 的正下方 底部和巡检趋势对其  -->
          <div class="ranking bg-white">
            <el-tabs v-model="activeName" @tab-click="handleClick">
              <el-tab-pane label="问题热度排名" name="first">
                <ul>
                  <li v-for="(rank, index) in qaRankings" :key="index">
                    <span class="ellipsis hotLi" >
                      <span :class="`rankIcon ${index > 2 ? 'greyBg' : ''}`">{{
                        index + 1
                      }}</span>
                      <span
                        :class="`rank-name ${index > 2 ? 'greyColor' : ''}`"
                        >{{ rank.name }}</span
                      >
                    </span>
                    <span
                      :class="`rank-value ${index > 2 ? 'greyColor' : ''}`"
                      >{{ rank.value }}</span
                    >
                  </li>
                </ul>
              </el-tab-pane>
              <el-tab-pane label="点赞排名" name="second">
                <ul>
                  <li v-for="(rank, index) in qaRankings" :key="index">
                    <span  class="ellipsis hotLi" >
                      <span :class="`rankIcon ${index > 2 ? 'greyBg' : ''}`">{{
                        index + 1
                      }}</span>
                      <span
                        :class="`rank-name ${index > 2 ? 'greyColor' : ''}`"
                        >{{ rank.name }}</span
                      >
                    </span>
                    <span
                      :class="`rank-value ${index > 2 ? 'greyColor' : ''}`"
                      >{{ rank.value }}</span
                    >
                  </li>
                </ul>
              </el-tab-pane>
            </el-tabs>
          </div>
        </div>
      </el-col>
    </el-row>

    <el-row :gutter="10">
      <el-col :xs="24" :sm="24" :md="12" :lg="12" :xl="12">
        <div class="report-distribution bg-white">
          <div class="distribution-title">知识库分布</div>
          <div id="distributionChart" style="height: 300px"></div>
        </div>
      </el-col>
      <el-col :xs="24" :sm="24" :md="12" :lg="12" :xl="12">
        <div class="failed-items bg-white">
          <div class="failed-title">知识类别分布</div>
          <div id="failedChart" style="height: 300px"></div>
        </div>
      </el-col>
    </el-row>
  </div>
</template>

<script>
import * as echarts from "echarts";
import {
  getMetric,
  getTrend,
  getDistributionKnowledge,
  getDistributionType,
  getQaHeat,
} from "@/api/index";
export default {
  name: "Index",
  data() {
    return {
      selectedYear: "2025",
      activeName: "first",
      metric: {
        fileCount: 0,
        fileNewCount: 0,
        flagCount: 0,
        knowledgeCount: 0,
      },
      yearList: [2025],
      messages: [
        { type: "系统", content: "新增内容尚未通过审核，点击查看更多详情" },
        { type: "系统", content: "新增内容尚未通过审核，点击查看更多详情" },
        { type: "系统", content: "新增内容尚未通过审核，点击查看更多详情" },
        { type: "系统", content: "新增内容尚未通过审核，点击查看更多详情" },
        { type: "系统", content: "新增内容尚未通过审核，点击查看更多详情" },
      ],
      qaRankings: [],
      trendChart: null,
      distributionChart: null,
      failedChart: null,
    };
  },
  created() {
    this.getData();
  },
  methods: {
    handleClick() {},
    getData() {
      getMetric().then((res) => {
        if (res.code === 200) {
          this.metric = res.data;
        }
      });
      getTrend().then((res) => {
        if (res.code === 200) {
          this.initTrendChart(res.data)
        }
      });
      getDistributionKnowledge().then((res) => {
        if (res.code === 200) {
          this.initDistributionChart(res.data);
        }
      });
      getDistributionType().then((res) => {
        if (res.code === 200) {
          this.initFailedChart(res.data);
        }
      });
      getQaHeat().then((res) => {
        if (res.code === 200) {
          this.qaRankings = res.data;
        }
      });

      window.addEventListener("resize", () => {
        this.failedChart.resize();
        this.distributionChart.resize();
        this.trendChart.resize();
      });
    },
    initTrendChart(data) {
      this.trendChart = echarts.init(document.getElementById("trendChart"));
      const option = {
        xAxis: {
          type: "category",
          data: data.dateList,
        },
        yAxis: {
          type: "value",
        },
        series: [
          {
            data: data.countList,
            type: "line",
          },
        ],
      };
      this.trendChart.setOption(option);
    },
    initDistributionChart(data) {
      this.distributionChart = echarts.init(
        document.getElementById("distributionChart")
      );
      const option = {
        series: [
          {
            type: "pie",
            radius: ["20%", "60%"],
            // avoidLabelOverlap: false,
            padAngle: 5,
            itemStyle: {
              borderRadius: 4,
            },
            data:data,
          },
        ],
      };
      this.distributionChart.setOption(option);
    },
    initFailedChart(data) {
      this.failedChart = echarts.init(document.getElementById("failedChart"));
      const option = {
        series: [
          {
            name: "Access From",
            type: "pie",
            padAngle: 15,
            radius: ["20%", "60%"],
            itemStyle: {
              borderRadius: 4,
            },
            data: data,
          },
        ],
      };
      this.failedChart.setOption(option);
    },
  },
};
</script>

<style scoped lang="scss">
.merchant-inspection {
  background: #f2f2f2;
  padding: 10px;
}
.bg-white {
  background: #ffffff;
  border-radius: 12px 12px 12px 12px;
  ul{
    height: 144px;
    overflow: auto;
  }
}
.el-main {
  padding: 0;
  display: flex;
  flex-wrap: wrap;
}

.metric-statistics {
  height: 130px;
  margin-bottom: 10px;
  padding: 20px;
  .title {
    font-size: 16px;
    color: #1c1c2a;
    line-height: 20px;
    margin-bottom: 10px;
  }
  .metric-content {
    display: flex;
    justify-content: space-around;
  }
}

.metric-item {
  text-align: center;
  display: flex;
  width: 25%;
  justify-content: space-around;
  align-items: center;
  border-right: 1px dashed #ccc; /* 添加虚线边框 */
  padding: 0 10px;
  &:last-child {
    border-right: none; /* 移除最后一个项的底部边框 */
    // margin-bottom: 0; /* 移除最后一个项的底部外边距 */
  }
  // .knowledge {
  //   color: #388eff;
  // }
  // .tags {
  //   color: #ff8716;
  // }
  // .document {
  //   color: #00d0af;
  // }
  // .addKnowledge {
  //   color: #009fd6;
  // }
  // .knowledgeIcon {
  //   background: #388eff;
  // }
  // .tagsIcon {
  //   background: #ff8716;
  // }
  // .documentIcon {
  //   background: #00d0af;
  // }
  // .addKnowledgeIcon {
  //   background: #009fd6;
  // }
  .metric-label {
    font-size: 14px;
    color: #6a74a5;
    line-height: 20px;
  }
  i {
    font-size: 24px;
    line-height: 42px;
    width: 42px;
    height: 42px;
    border-radius: 50%;
    color: #fff;
  }

  .metric-value {
    font-size: 24px;
    margin-bottom: 10px;
  }
}
.flexDiv {
  display: flex;
}
.top {
  display: flex;
  justify-content: space-around;
}
.inspection-trend {
  padding: 20px;
  margin-bottom: 10px;
  background-color: white;
  height: 380px;
}

.message-reminder {
  height: 216px;
  padding: 20px;
  margin-bottom: 10px;
  background-color: white;
  .reminder-header {
    display: flex;
    justify-content: space-between;
  }
  li {
    margin-bottom: 10px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    cursor: pointer;
  }
  font-size: 14px;
  color: #6a74a5;
  .msg-type {
    color: #12b3bf;
    padding: 2px 10px;
    margin-right: 10px;
    background: #dff7f9;
    border-radius: 12px 12px 12px 12px;
  }
  .msg-content {
  }
}
ul {
  list-style: none;
  padding: 0;
}
.ranking {
  height: 296px;
  padding: 20px;
  margin-bottom: 10px;
  background-color: white;
  .rankIcon {
    display: inline-block;
    width: 24px;
    height: 24px;
    border-radius: 12px;
    background: #5c64f7;
    color: #fff;
    line-height: 24px;
    text-align: center;
    margin-right: 10px;
    &.greyBg {
      background: #c8c8c8;
    }
  }
  .hotLi{
    width: 240px;
    
  }
  .rank-value {
    margin-right: 12px;
  }

  li {
    display: flex;
    justify-content: space-between;
    color: #5c64f7;
    font-size: 14px;
    cursor: pointer;
    .greyColor {
      color: #545454;
    }
  }
}

.report-distribution {
  padding: 20px;
  margin-bottom: 10px;
  background-color: white;
}

.failed-items {
  padding: 20px;
  margin-bottom: 10px;
  background-color: white;
}

.trend-title,
.reminder-title,
.ranking-title,
.distribution-title,
.failed-title {
  display: flex;
  justify-content: space-between;
  align-items: center;
  // margin-bottom: 10px;
}

.ranking ul {
  list-style: none;
  padding: 0;
  overflow: auto;
  height: 180px;
}

.ranking li {
  display: flex;
  align-items: center;
  margin-bottom: 10px;
}

.ranking li i {
  margin-right: 10px;
}

.el-select {
  width: 100px;
}
</style>